package com.example.walletmodule.conrtoller;

import com.example.walletmodule.entity.UserEntity;
import com.example.walletmodule.entity.WalletEntity;
import com.example.walletmodule.service.WalletService;
import com.example.walletmodule.util.CommonResult;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;


/**
 * 用户钱包主体表
 *
 * @author wangqiao
 * @date 2023-02-21 16:40:42
 */
@RestController
@RequestMapping("wallet")
public class WalletController {
    @Resource
    private WalletService walletService;

    @GetMapping("queryWalletMoney")
    public CommonResult<BigDecimal> queryWalletMoney(@RequestBody UserEntity user){
        if(ObjectUtils.isEmpty(user)||ObjectUtils.isEmpty(user.getUserId())){
            return CommonResult.fail(null,"查询余额失败");
        }
        // 余额查询
        WalletEntity wallet = walletService.getByUserId(user.getUserId());
        return CommonResult.success(wallet.getWalletBalance(),"查询余额成功");
    }



}
